/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.api.model;

import org.proteusframework.api.config.IConfigProperty;
import org.proteusframework.util.Assert;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Concrete version descriptor implementation that maintains an immutable set of version descriptor properties,
 * including a qualified name, a version, and a collection of configuration properties.
 *
 * @author Tacoma Four
 */
public class VersionDescriptor implements IVersionDescriptor
{
    /**
     * Immutable qualified name assigned to the version descriptor.
     */
    protected IQualifiedName qualifiedName;

    protected IVersion version;

    protected Collection<IConfigProperty> configurationProperties = new ArrayList<IConfigProperty>();


    /**
     * Constructs a version descriptor from the given qualified name, version, and collection of configuration
     * properties.
     *
     * @param qualifiedName           Qualified name
     * @param version                 Version stamp
     * @param configurationProperties Non-null collection of configuration properties
     */
    public VersionDescriptor(IQualifiedName qualifiedName, IVersion version,
                             Collection<IConfigProperty> configurationProperties)
    {
        Assert.parameterNotNull(version, "Parameter 'version' must not be null");

        this.qualifiedName = qualifiedName;
        this.version = version;

        if (null != configurationProperties)
            this.configurationProperties.addAll(configurationProperties);
    }

    /**
     * Constructs a version descriptor from the given qualified name and version, with an empty set of configuration
     * properties.
     *
     * @param qualifiedName Qualified name
     * @param version       Version stamp
     */

    public VersionDescriptor(IQualifiedName qualifiedName, IVersion version)
    {
        this(qualifiedName, version, null);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public IVersion getVersion()
    {
        return version;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public IQualifiedName getQualifiedName()
    {
        return qualifiedName;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Collection<IConfigProperty> configurationProperties()
    {
        return configurationProperties;
    }
}
